<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <title>新增pid</title>
        <link rel="stylesheet" href="__STATIC__/layui/css/layui.css" media="all">
        <script src="__STATIC__/index/js/jquery-3.2.1.js"></script>
        <script src="__STATIC__/layui/layui.js"></script>
    </head>
    <body>
        <form class="layui-form"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
            <div class="layui-form-item">
                <label class="layui-form-label">绑定有效PID</label>
                <div class="layui-input-block">
                    <input type="text" name="pid" placeholder="请输入" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="*" id="button_from">立即提交</button>
                </div>
            </div>
            <!-- 更多表单结构排版请移步文档左侧【页面元素-表单】一项阅览 -->
        </form>
        <script>
            layui.use('form', function(){
                var form = layui.form;
                form.on('submit(*)', function(data){
                    var field = data.field;
                    var pid = field.pid;
                    if(pid==''){
                    	layui.use('layer', function(){
				        var layer = layui.layer;
				        layer.alert('请输入PID', {icon: 2});
					    });              
			 		   return false;
                    }
                     $('#button_from').attr('disabled','disabled');	 
                    $.ajax({
                    	type:"post",
                    	url:"{:url('market/insertpidNew')}",
                    	data:{pid:pid},
                    	success:function(res){
                    		  if(res.code==0){
	                		   	  layui.use('layer', function(){
					              var layer = layui.layer;
					              layer.alert(res.msg, {icon: 2},function(){
					              	$('#button_from').removeAttr('disabled');
					              	location.reload(); 
					              });
					              });              
			 		        return false;
                		   }else if(res.code==1){
                		   	       layui.use('layer', function(){
					               var layer = layui.layer;
					               layer.alert(res.msg, {icon: 1},function(){
					               	$('#button_from').removeAttr('disabled');
									window.parent.getChild();
					              });
					              });  
					        return false;
                		   }
                    		
                    	}
                    });
                    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                });
            });
        </script>
    </body>
</html>
